<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath %>" />
    <title>权限数据列表</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<jsp:include page="../util/commScript.jsp">
	   <jsp:param value="<%=basePath %>" name="basePath"/>
	</jsp:include>
  </head>
  <body>
  <div class="place">
    <span>位置：</span>
	    <ul class="placeul">
		    <li><a href="javascript:void(0)">首页</a></li>
		    <li><a href="javascript:void(0)">系统管理</a></li>
		    <li><a href="javascript:void(0)">权限管理</a></li>
	    </ul>
	</div>
  <div id="permissionListPage"  class="easyui-layout"  data-options="fit:'true'">
    <div data-options="region:'center',noheader:'false',border:false" title="Center">
		 <div id="permissionList"></div>
		    <div id="permissionTools">
			    <!-- 表格工具栏 -->
				<div class="tb_toolbar" >
					<a href="javascript:addPermission('')"   class="easyui-linkbutton"  data-options="iconCls:'icon-add'">新增权限</a>
					<a href="javascript:batchDeletePermission()" class="easyui-linkbutton"  data-options="iconCls:'icon-no'">批量删除</a>
				    <a href="javascript:seachData()" class="easyui-linkbutton"  data-options="iconCls:'icon-search'">检索</a>
				    <!-- <a href="javascript:batchMove()" class="easyui-linkbutton" data-options="iconCls:'icon-cut'">批量移动</a> -->
			        <a href="javascript:batchCopy()" class="easyui-linkbutton" data-options="iconCls:'icon-filter'">批量复制</a>
				</div>
			    <!-- 表格行工具栏 -->
				<div class="row_toolbar" style="display: none">
					<a href="javascript:editPermission('#ID#')" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"></a>
					<a href="javascript:delPermission('#ID#')" class="easyui-linkbutton" data-options="iconCls:'icon-no',plain:true"></a>
					<a href="javascript:setOrderVal('up','#ID#')" class="easyui-linkbutton" data-options="plain:false">向上↑</a>
					<a href="javascript:setOrderVal('down','#ID#')" class="easyui-linkbutton" data-options="plain:false">向下↓</a>
				</div>
		   </div>
    </div>
      <script type="text/javascript">
          var tableObject = $("#permissionListPage #permissionList");
          var basePath = getBasePath();
          $(function(){
        	  loadTableList();
          })
          
          //检索数据
          function seachData(){
        	  var permissionName = $("#permissionListPage input[name='permissionName']").val();
        	  tableObject.datagrid({
        		  queryParams: {
        			  permissionName:permissionName
    		      }
        	  })
          }
          
          function loadTableList(){
  	    	//向后台加载数据
  	    	tableObject.treegrid({
  	    		idField:'uuid',    
  	    	    treeField:'psmName',
  		        url:basePath+'/permission/getPermissionList4treeGrid.do',
  		        //远程请求数据的方式
  		        method:"post",
  		        fit:true,
  		        //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
  		        fitColumns:true,
  		        //调整列的位置
  		        resizeHandle:"right",
  		        //定义设置行的高度,根据该行的内容。设置为false可以提高负载性能
  		        autoRowHeight:"false",
  		        //工具栏
  		        toolbar:"#permissionTools .tb_toolbar",
  		        //boolean 是否显示斑马线效果。 
  		        striped:true,
  		        nowrap:false,
  		        rownumbers:true,//是否显示行号
  		        loadMsg:"数据加载中，请稍后...",
  		        singleSelect:false,
  		        checkOnSelect:true,
  		        //定义查找数据字段
  		        columns:[[
  		            {field:'id',checkbox:true},
  		            {field:'psmName',title:'权限名称',width:150},
  		            {field:'psmCode',title:'权限编码',width:105},
  		            {field:'psmUrl',title:'权限地址',width:150},
  		            {field:'psmIcon',title:'权限图标',width:150},
  		            {field:'parentName',title:'父级',width:100},
  		            {field:'orderNo',title:'序号',width:40},
  		            {field:'action',title:'操作',width:200,formatter:function(value, row, index) {
  		            	var reg=new RegExp("#ID#","g"); //创建正则RegExp对象
  		            	return $("#permissionTools .row_toolbar").html().replace(reg,row.id);
  					}}
  		        ]]
  		    });
          }
          
        //拷贝数据
        function batchCopy(){
        	//验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	        
  	    	var editDataFormArea = $("#editDataFormArea");
      		if(editDataFormArea.length==0){
      			$("<div id='editDataFormArea'></div>").prependTo("body");
      		}
      		
      		var _width  = $(window).width()-200;
      		var _height = $(window).height()-100;
      		var x_left = ($(window).width()-_width)/2;
      		var y_top = ($(window).height()-_height)/2;
      		
  	    	$("#editDataFormArea").window({
  	    	    title: '拷贝权限信息',
  	    	    width: _width,
  	    	    height: _height,
  	    	    iconCls:'icon-window',
  	    	    left:x_left,
  	    	    top:y_top,
  	    	    closed: false,
  	    	    cache: false,
  	    	    modal: true,
  	    	    onClose:function(){
				    $("#editDataFormArea").html("");
				    $("#editDataFormArea").remove();
				},
				href:basePath+"manage/xtsz/copyPermission.jsp"
  	    	});
        }
          
        //添加数据
  	    function addPermission(id){
  	        //验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	        
  	    	var editDataFormArea = $("#editDataFormArea");
      		if(editDataFormArea.length==0){
      			$("<div id='editDataFormArea'></div>").prependTo("body");
      		}
      		
      		var _width  = $(window).width()*0.95;
      		var _height = 460;
      		var x_left = ($(window).width()-_width)/2;
      		var y_top = ($(window).height()-_height)/2;
      		
  	    	$("#editDataFormArea").window({
  	    	    title: '新增权限信息',
  	    	    width: _width,
  	    	    height:_height,
  	    	    iconCls:'icon-window',
  	    	    left:x_left,
  	    	    top:y_top,
  	    	    closed: false,
  	    	    cache: false,
  	    	    modal: true,
  	    	    onClose:function(){
				    $("#editDataFormArea").html("");
				    $("#editDataFormArea").remove();
				},
				href:basePath+"manage/xtsz/editPermission.jsp?id="+id
  	    	});
  	    }
        
        //设置顺序
  	    function setOrderVal(setType,id){
  	    	$.post(basePath+"permission/setOrderVal.do",{setType:setType,id:id},
    		    	function(jsonData){
    					if(jsonData.code=="00"){
    						$.messager.alert('系统提示',jsonData.msg,'success');
    						var curRow = tableObject.datagrid("getSelected");
    						tableObject.treegrid('reload',curRow.parentUUID);
    					}else{
    						$.messager.alert('系统提示',jsonData.msg,'error');
    					}
      		 },"json");
  	    }
        
  	     //添加数据
  	    function editPermission(id){
  	    	var curRow = tableObject.datagrid("getSelected");
  	        //验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	        
  	    	var editDataFormArea = $("#editDataFormArea");
      		if(editDataFormArea.length==0){
      			$("<div id='editDataFormArea'></div>").prependTo("body");
      		}
      		
      		var _width = 658;
      		var _height = 340;
      		var x_left = ($(window).width()-_width)/2;
      		var y_top = ($(window).height()-_height)/2;
      		
  	    	$("#editDataFormArea").window({
  	    	    title: '新增权限信息',
  	    	    width: _width,
  	    	    height: _height,
  	    	    iconCls:'icon-window',
  	    	    left:x_left,
  	    	    top:y_top,
  	    	    closed: false,
  	    	    cache: false,
  	    	    modal: true,
  	    	    onClose:function(){
				    $("#editDataFormArea").html("");
				    $("#editDataFormArea").remove();
				},
				href:basePath+"manage/xtsz/updatePermission.jsp?id="+id+"&&parentUUID="+curRow.parentUUID
  	    	});
  	    }
          
        //删除单条数据	
  	    function delPermission(id){
        	//验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
  	    	$.messager.confirm('确认对话框', '此操作将永久删除该条数据,请确认是否继续操作？', function(flag){
      			if (flag){
      				$.post(basePath+"permission/delPermission.do",{id:id},
      		    	function(jsonData){
      					if(jsonData.code=="00"){
      						$.messager.alert('系统提示','删除成功！','success');
      						var curRow = tableObject.datagrid("getSelected");
      						tableObject.treegrid('reload',curRow.parentUUID);
      					}else{
      						$.messager.alert('系统提示',jsonData.msg,'error');
      					}
      		    	},"json");
      			}
      		});
  	    }
          
        //批量删除
  	    function batchDeletePermission(){
  	    	//验证是否登录--开始
  	    	if(!checkLoginStatus()){return;}
  	        //验证是否登录--结束
        	
  	    	var ids = [];
  			var rows = tableObject.treegrid('getSelections');
  			if(rows.length<1){
  				$.messager.alert('系统提示','请选中数据后再进行操作！','error');
  				return;
  			}
  			
  			//获取datagrid选中行
  			for (var i = 0; i < rows.length; i++) {
  				ids.push(rows[i].id);
  			}
  			ids = ids.join(',');
  			$.messager.confirm('确认对话框', '此操作将永久删除被选中的数据,请确认是否继续操作？', function(flag){
      			if (flag){
      				$.post(basePath+"permission/delMorePermission.do",{ids:ids},
      		    	function(jsonData){
      					if(jsonData.code=="00"){
      						$.messager.alert('系统提示','删除成功！','success');
      						//删除成功后重新加载表格
      						tableObject.treegrid('reload'); 
      					}else{
      						$.messager.alert('系统提示','删除失败！','error');
      					}
      		    	},"json");
      			}
      		});			
  		}
      </script>
      </div>
  </body>
</html>
